package com.terrace.core.common.service.impl;

import java.util.Date;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.terrace.core.common.dao.GeneralDao;
import com.terrace.core.common.model.GeneralModel;
import com.terrace.core.common.model.UserInfo;
import com.terrace.core.common.service.GeneralService;

@Transactional
public class GeneralServiceImpl<D extends GeneralDao<M>, M extends GeneralModel> implements GeneralService<M> {

	@Autowired
	protected D dao;

	@Override
	public int save(M model) {
		Session session =SecurityUtils.getSubject().getSession();
		UserInfo userInfo = (UserInfo) session.getAttribute("USER_SESSION_KEY");
		model.setCreateDate(new Date());
		model.setCreateUserId(userInfo.getUserId());
		return this.dao.save(model);
	}

	@Override
	public int delete(Integer id) {
		return this.dao.delete(id);
	}

	@Override
	public int update(M model) {
		return this.dao.update(model);
	}

	@Override
	public M selectById(Integer id) {
		return this.dao.selectById(id);
	}

}
